home *** CD-ROM | disk | FTP | other *** search
/ MacTech 1 to 12 / MacTech-vol-1-12.toast / Source / MacTech® Magazine / Volume 10 - 1994 / 10.06 Jun 94 / PoweringUp < prev   
Encoding:
Text File  |  1994-05-24  |  2.2 KB  |  60 lines  |  [TEXT/MPS ]

  1. From the Mail Bag
  2. After looking at the April issue (with the articles on the Code Fragment 
  3. Manager and calling 68K code from PowerPC code), some developers have 
  4. asked “how do I call PowerPC code from 68K code?”
  5.  
  6. If you want to leave the 68K code alone, you need to construct one or 
  7. more Routine Descriptors in the PowerPC code and pass the addresses of 
  8. these (Universal Procedure Pointers, in other words) to the 68K code. 
  9. Then, the 68K code can simply jump through the universal pointer.
  10.  
  11. The PowerPC code can provide a function whose job it is to construct 
  12. these pointers (as shown in the April article), or if the code is in 
  13. a resource, can use the definitions in “Mixed Mode.r” to place a 
  14. Routine Descriptor in front of the code. 
  15.  
  16. If you want to leave the PowerPC code alone, the 68K code can use a 
  17. Mixed Mode A-Trap to create the routine descriptor. The bad news is 
  18. this: blindly calling “NewRoutineDescriptor” won’t do what you want. 
  19. (When compiling for the 68K, NewRoutineDescriptor is an “null” macro 
  20. that just returns the supplied procedure pointer.) The solution is 
  21. to copy the definition of NewRoutineDescriptor, and convert the 
  22. contents of the “THREEWORDINLINE” macro into an actual inline.
  23.  
  24. The result of all this work looks like this:
  25.  
  26.  
  27. #if USES68KINLINES
  28.     pascal UniversalProcPtr InlineNewRoutineDescriptor(
  29.             ProcPtr theProc,
  30.             ProcInfoType theProcInfo,
  31.             ISAType theISA)
  32.          = {0x303C, 0x0000, 0xAA59};
  33. #endif
  34.  
  35. typedef void (*OurProcPtr)(short);
  36.  
  37. void CallPowerProc (ProcPtr powerCodeAddress, 
  38.                     short onlyParameter)
  39. {
  40.     OurProcPtr        ourUPP;
  41.     short            procInfo = kCStackBased |
  42.                     STACK_ROUTINE_PARAMETER(1, kTwoByteCode);
  43.  
  44. #if USES68KINLINES
  45.     ourUPP=(OurProcPtr) InlineNewRoutineDescriptor( 
  46.             powerCodeAddress,
  47.             procInfo,
  48.             kPowerPCISA);
  49. #else
  50.     // We’re compiling for PowerPC -- see the comments below
  51.     ourUPP= (OurProcPtr) NewRoutineDescriptor(
  52.             powerCodeAddress,
  53.             procInfo,
  54.             kPowerPCISA);
  55. #endif
  56.     CallUniversalProc((UniversalProcPtr)ourUPP, procInfo, onlyParameter);    
  57.     // If you *know* this is 68K code, you could just use:  ourUPP(onlyParameter)
  58.     // but using CallUniversalProc covers the possibility that this could be compiled 
  59.     // for PowerPC some day without changing the sources
  60. }